package com.study.design.model.structPattern.composite.example;

import java.util.ArrayList;
import java.util.List;

/**
* @Name: Folder
* @Description: 容器组件：文件夹
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-2-11 上午11:31:49 
* @Version: V1.0
 */
public class Folder implements AbstractFile {
	
	private String name ;
	
	private List<AbstractFile> list = new ArrayList<AbstractFile>() ;

	public Folder(String name) {
		this.name = name;
	}
	
	public void add(AbstractFile file) {
		list.add(file) ;
	}
	
	public void remove(AbstractFile file) {
		list.remove(file) ;
	} 
	
	public AbstractFile getChile(int index) {
		return list.get(index) ;
	}

	@Override
	public void killVirus() {
		System.out.println("--文件夹:" + name + ",进行查杀！"); 
		for(AbstractFile child : list) {	
			child.killVirus() ;	//递归查杀孩子组件
		}
	}

}
